import apiList from '../api/api'

const defaultData = () => ({
  // 国突预警
  moduleVisible: {
    //站点
    zdModule: true,
    //网格
    wgModule: false
  },
  componentsVisible: {
    // 国家站
    gjz: false,
    // 区域站
    qyz: false,
    // 站点名称
    zdmc: false,
    // 站号
    zh: false,
    // 县名
    xm: false,
    areaCode: '',
    labels: '全部',
    //站点
    zd: false,
    //网格
    wg: false,
    //色斑图
    sbt: false
  },
  // 地图加载
  mapLoading: false,
  earlyType: [],
  warnType: '',
  level: 0,
  statisticsData: [],
  warningInfoData: []
})

export const useWarningStore = defineStore({
  id: 'warning',
  state: () => {
    return defaultData()
  },
  getters: {},
  actions: {
    async getWarningStatistics() {
      const { data } = await apiList.getWarningLevelNumStatistics({
        administrationLevel: this.level,
        warnType: this.warnType,
        areaCode:
          this.componentsVisible.areaCode == '全部'
            ? ''
            : this.componentsVisible.areaCode
      })
      this.statisticsData = data
    },
    async getWarningInfoData() {
      const { data } = await apiList.getWarningInfoList({
        administrationLevel: this.level,
        warnType: this.warnType,
        areaCode:
          this.componentsVisible.areaCode == '全部'
            ? ''
            : this.componentsVisible.areaCode
      })
      this.warningInfoData = data
    },
    // 销毁 并初始化数据
    handleUnmountedInitData() {
      const defaultDataObj = defaultData()
      Object.keys(defaultDataObj).forEach(item => {
        this[item] = defaultDataObj[item]
      })
    }
  }
})
